package com.itbour.service.tg.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.common.util.StringUtils;
import com.itbour.dao.tg.SceneInfoDao;
import com.itbour.dto.tg.SceneInfoDto;
import com.itbour.service.tg.SceneInfoService;

/** 场景展示 接口实现
 */
public class SceneInfoServiceImpl implements SceneInfoService {
	private SceneInfoDao sceneInfoDao;

	@Override
	public Page pageQuery(Map<String, Object> parm, Integer pageNo,
			Integer pageSize) {
		JspPage jpage=null;
		/*
		 * (pageNo-1)*pageSize limit(0,pageSize)
		 */
		int skipPage=JspPage.getStartOfPage(pageNo, pageSize);//获取起始位置0,10,20,30
		int totalCount=sceneInfoDao.senceTotalCount(parm);//获取总条数
		while(totalCount >0 && totalCount <= skipPage){//如果起始位置数大于总数
			skipPage= skipPage - pageSize;//
			pageNo = pageNo -1;
		}
		parm.put("pageSize", pageSize);//页面查看显示条数
		parm.put("skipResult", skipPage);//起始位置数
		List<SceneInfoDto> data=sceneInfoDao.findSceneInfo(parm);
	    jpage=new JspPage(skipPage,totalCount,pageSize,data);
		return jpage;
	}

	@Override
	public void saveSceneInfo(SceneInfoDto sc) {
		Map<String, Object> param=new HashMap<String, Object>();
		param.put("type", sc.getType());
		param.put("title", sc.getTitle());
		param.put("desc", sc.getDesc());
		param.put("image", sc.getImage());
		param.put("url", sc.getUrl());
		param.put("order", sc.getOrder());
		param.put("update_by", sc.getUpdate_by());
		sceneInfoDao.insertSceneInfo(param);
	}

	@Override
	public void updataSceneInfo(Map<String, Object> param) {
		sceneInfoDao.updateSceneInfo(param);
	}


	@Override
	public List<SceneInfoDto> findOneSceneInfo(Map<String, Object> parm) {
		return sceneInfoDao.findOneSeceInfo(parm);
	}
	
	
	@Override
	public void deleteSceneInfo(String ids) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("ids", StringUtils.listToString2(StringUtils.stringToList2(ids)));
		sceneInfoDao.deleteSceneInfo(param);
	}
	
	public SceneInfoDao getSceneInfoDao() {
		return sceneInfoDao;
	}
	public void setSceneInfoDao(SceneInfoDao sceneInfoDao) {
		this.sceneInfoDao = sceneInfoDao;
	}
}
